<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 最小时间差

```
给定一个 24 小时制（小时:分钟 "HH:MM"）的时间列表，找出列表中任意两个时间的最小时间差并以分钟数表示。
 -->
</head>
<body>
  <script>
    var findMinDifference = function(timePoints) {
      if(!Array.isArray(timePoints)) return
      const timeArray = timePoints.map((item)=>{
        return item = parseInt(item.substr(0,2)) * 60 + parseInt(item.substr(3,2))
      }).sort((a,b)=>{return a-b})
      let numList = []
      timeArray.forEach((item,i)=>{
        if(i>0){
          numList.push(Math.min(Math.abs(timeArray[i] - timeArray[i-1]),1440-Math.abs(timeArray[i] - timeArray[i-1])))
        }
      })
      const lastChild = Math.abs(timeArray[timeArray.length-1] - timeArray[0])
      numList.push(Math.min(lastChild,1440-lastChild))
      numList.sort((a,b)=>{return a-b})
      return numList[0]
    };
     let data = ["00:00","23:59","00:00"]
    //let data = ["23:59","00:00"]
    console.log(findMinDifference(data)); 

  </script>
</body>
</html>